﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using OgilvyOne.BLL;
using OgilvyOne.Model;

public partial class admin_allergy_doctor_FAQ_add : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string Layerid = Request.Params["layerId"];
            this.headers.Text = "FAQ管理";
            try
            {
                if (Request.Params["id"] != null && Request.Params["id"] != "")
                {
                    DataTable dt = BLLArticleInfo.getFAQ(Request.Params["id"]);
                    foreach (DataRow row in dt.Rows)
                    {
                        this.title.Text = row["title"].ToString();
                        this.Type.SelectedValue = row["type"].ToString();
                        this.status.SelectedValue = row["status"].ToString();
                        this.answer.Text = row["answer"].ToString();
                        this.content.Text = row["content"].ToString();
                        this.id.Value = row["id"].ToString();
                        this.DropDownList1.SelectedItem.Text = row["doctorName"].ToString();
                        this.modtime.Text = row["modtime"].ToString();
                        this.more_rbtn.SelectedValue = row["ismore"].ToString();
                        this.recommend_rbtn.SelectedValue = row["isrecommend"].ToString();
                    }
                }
            }
            catch (Exception)
            { }
            //医生绑定
            DataTable dr = BLLArticleInfo.getdr();
            foreach (DataRow row in dr.Rows)
            {
                DropDownList1.Items.Add(row["name"].ToString());
            }
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        int id = 0;
        if (this.id.Value != null && this.id.Value != "")
        {
            id = int.Parse(this.id.Value);
        }
        if (id > 0)
        {

            string title1 = this.title.Text;
            string type2 = this.Type.SelectedValue;
            string status3 = this.status.SelectedValue;
            string answer4 = this.answer.Text;
            string content5 = this.content.Text;
            string id6 = this.id.Value;
            string doctorNm = this.DropDownList1.SelectedItem.Text;
            string modtime = this.modtime.Text;//回答时间
            string updatetime = DateTime.Now.ToString();
            string ismore = this.more_rbtn.SelectedValue;
            string isrecommend = this.recommend_rbtn.SelectedValue;
            BLLArticleInfo.upFaq(type2, title1, content5, answer4, status3, doctorNm, modtime, updatetime,ismore,isrecommend, id6);
            Response.Redirect("FAQ_list.aspx?columnid=" + Request.Params["columnid"] + "&layerId=" + Request.Params["layerId"]);

        }
        else
        {
            nestle_doctor_FAQ info = new nestle_doctor_FAQ();
            info.Title = this.title.Text;
            info.Type = this.Type.SelectedValue; ;
            info.Content = this.content.Text;
            info.Answer = this.answer.Text;
            info.Status = this.status.SelectedIndex.ToString();
            info.DoctorName = this.DropDownList1.SelectedItem.Text;
            info.Ismore = this.more_rbtn.SelectedValue.ToString();
            info.Isrecommend = this.recommend_rbtn.SelectedValue.ToString();
            if (this.modtime.Text == null && this.modtime.Text == "")
            {
                info.Modtime = DateTime.Now.ToShortDateString();
            }
            else
            {
                info.Modtime = this.modtime.Text;
            }
            if (this.Type.SelectedValue == "0")
            {
                Response.Write("<script>alert('请选择问题类型');</script>");
            }
            if (title.Text == null || title.Text == "")
            {
                Response.Write("<script>alert('请输入问题标题');</script>");
            }
            else
            {
                BLLArticleInfo.insertFaq(info);
                Response.Redirect("FAQ_list.aspx?columnid=" + Request.Params["columnid"] + "&layerId=" + Request.Params["layerId"]);
            }
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("FAQ_list.aspx?columnid=" + Request.Params["columnid"] + "&layerId=" + Request.Params["layerId"]);
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        Calendar1.Visible = true;
    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        this.modtime.Text = Calendar1.SelectedDate.ToShortDateString();
        Calendar1.Visible = false;
    }
}
